package com.example.common.controller;

import com.example.common.feign.ProducerService;
import com.example.common.service.FileService;
import com.example.common.utils.RestResponse;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;

/**
 * @author: mtl
 * @Date: 2022/1/12 18:45
 * @Description: 公共服务 API
 */
@RestController
public class CommonController {

    @Resource
    ProducerService producerService;
    @Resource
    FileService fileService;

    @GetMapping("/1")
    public String test() {
        String test = producerService.test(1);
        return test;
    }

    @GetMapping("/2")
    public String test2(){
        return producerService.test2();
    }

    @ResponseBody
    @GetMapping("/3")
    public String test3(){
        return producerService.test3();
    }

    @RequestMapping("/upload")
    @ResponseBody
    public RestResponse handleFileUpload(@RequestParam("file") MultipartFile file) {
        RestResponse res = fileService.handleFileUpload(file);
        return res;
    }

    @RequestMapping("/download")
    public void downloadFile(Integer id, HttpServletResponse response){
        fileService.downloadFile(id, response);
    }
}
